/* eslint-disable */
// 目录
const {
    getCatalogueById,   // 根据id 查询目录
    getCatalogueList,   //  查询目录列表
    createCatalogue,   // 添加目录
    editCatalogue,   // 编辑目录
    removeCatalogue,   // 删除目录
    getCatalogueAll,    // 获取全部数据
} = require("../../service/catalogue/catalogue")


exports.catalogueApi = async ctx => {
    // 获取url 字段 继而判断接下来操作
    let url = ctx.request.url.split("/");
    let urlKey = url[2].split("?")[0]
    const { id } = ctx.params || "";
    const { title, updator, creator } = ctx.request.body || "";
    let res;
    switch (ctx.request.method) {
        case "GET": if (urlKey == "byid") {
            res = await getCatalogueById({ id })
        } else if(urlKey == "list"){
            res = await getCatalogueList()
        }else if(urlKey == 'all'){
            res = await getCatalogueAll()
        }; break;
        case "POST": res = await createCatalogue({ title, creator }); break;
        case "DELETE": res = await removeCatalogue({ id }); break;
        case "PUT": res = await editCatalogue({ id, title, updator }); break;
        default: res = {msg:"操作失败", code:"400"}
    }
    ctx.body = res
}